var ReportIndexCtrl = ['$scope', '$rootScope', function ($scope, $rootScope) {
        $scope.menu_list = [{
                name: $rootScope.language.TIP_REPORT_SPKCCX,
                url: "#report/spkc",
                id: "spkc curr",
                style: "spkc",
                show: $rootScope.purview['\/SpkcCtrl'].show
            }, {
                name: $rootScope.language.TIP_REPORT_KCZFX,
                url: "#report/kczfx",
                id: "kczfx curr",
                style: "kczfx",
                show: $rootScope.purview['\/KczfxCtrl'].show
            }, {
                name: $rootScope.language.TIP_REPORT_JXCFX,
                url: "#report/jxcfx",
                id: "jxcfx curr",
                style: "jxcfx",
                show: $rootScope.purview['\/JxcfxCtrl'].show
             }, {
                name: $rootScope.language.TIP_REPORT_ARFX,
                url: "#report/arfx",
                id: "arfx curr",
                style: "arfx",
                show: $rootScope.purview['\/ArfxCtrl'].show
             }, {
                name: $rootScope.language.TIP_REPORT_RXPH,
                url: "#report/rxph",
                id: "rxph curr",
                style: "rxph",
                show: $rootScope.purview['\/RxphCtrl'].show
            }, {
                name: $rootScope.language.TIP_REPORT_DGYJ,
                url: "#report/dgyj",
                id: "dgyj curr",
                style: "dgyj",
                show: $rootScope.purview['\/DgyjCtrl'].show
            }, {
                name: $rootScope.language.TIP_REPORT_LSFX,
                url: "#report/lsfx",
                id: "lsfx curr",
                style: "lsfx",
                show: $rootScope.purview['\/LsfxCtrl'].show
            }, {
                name: $rootScope.language.TIP_REPORT_ZFGC,
                url: "#report/zfgc",
                id: "zfgc curr",
                style: "zfgc",
                show: 1//$rootScope.purview['\/ZfgcCtrl'].show
            }
            
            /*,{
             name: $rootScope.language.TIP_REPORT_MORE,
             url: "#report/more",
             id: "more curr",
             style: "more"
             }*/];
    }];
//商品库存查询
var SpkcCtrl = ['$scope', '$rootScope', 'BaseGoods', 'ngDialog', '$rootScope', '$location', function ($scope, $rootScope, BaseGoods, ngDialog, $rootScope, $location) {

        if ($rootScope.purview['\/SpkcCtrl'].show == 0) {
            switch (1) {

                case $rootScope.purview['\/KczfxCtrl'].show:
                    $location.path('/report/kczfx');
                    break;
                case $rootScope.purview['\/JxcfxCtrl'].show:
                    $location.path('/report/jxcfx');
                    break;
                case $rootScope.purview['\/ArfxCtrl'].show:
                    $location.path('/report/arfx');
                    break;
                case $rootScope.purview['\/RxphCtrl'].show:
                    $location.path('/report/rxph');
                    break;
                case $rootScope.purview['\/DgyjCtrl'].show:
                    $location.path('/report/dgyj');
                    break;
                case $rootScope.purview['\/LsfxCtrl'].show:
                    $location.path('/report/lsfx');
                    break;
            }
        }

//        $rootScope.purviewCheckChange('');
        $scope.curr = 'spkc curr';
        $scope.input_keywords = '';
        var window_id = 0;
        //默认显示图表
        $scope.chart_cur = 1;
        $scope.table_cur = 0;
        //加载百度图表
        require.config({
            paths: {echarts: './script/echarts'}
        });

        //搜索商品
        $scope.search_goods = function (keywords) {
            if (keywords == '') {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_CODE});
                return;
            }
	        var key = new String(keywords);
	        if ('' == keywords || key.length < 3) {
		        baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_INPUT_MORE_THREE});
	            return;
	        }

	        BaseGoods.get_sku_by_code(keywords).then(function (response) {
	            if (Object.keys(response).length == 1) {
                    $scope.goods = response[0];
                    getStockNumAndRoadNum(response[0]);
                    stock_change(response[0]);
                } else if (Object.keys(response).length == 0) {
                    $scope.goods = response;
                    getStockNumAndRoadNum(response);
                    stock_change(response);
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_CANT_FOUND_RESULT});
                    return;
                } else if (Object.keys(response).length > 1) {
                    $scope.goods_select_data = response;
                    window_id = ngDialog.open({closeByDocument: false,
                        template: './html/component/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
//                      closeByDocument: false
                        trapFocus: false
                    });
                }
            });
        };

        //图标显示
        $scope.chart_show = true;
        $scope.chart_list = function () {
            if ($scope.chart_show) {
                $scope.chart_show = false;
            } else {
                $scope.chart_show = true;
            }
        };

        //列表显示
        $scope.table_show = true;
        $scope.table_list = function () {
            if ($scope.table_show) {
                $scope.table_show = false;
            } else {
                $scope.table_show = true;
            }
        };
        //弹框处理
        $scope.goods_select_click = function (goods) {
            $scope.goods = goods;
            getStockNumAndRoadNum(goods);
            stock_change(goods);
            ngDialog.close(window_id);
        };


        //私有方法==========================================
        //获取在库库存和在途库存
        var getStockNumAndRoadNum = function (goods) {
            BaseGoods.getStockNumAndRoadNum_by_api_skus(goods).then(function (response) {
                if (response.data.status == 1) {
                    var data = response.data.data;
                    $scope.stock = data[0];  //该sku对应的库存信息
                } else {
                    $scope.stock = {};
                }
            });
        };


        //查询并显示三十天库存变化情况
        var stock_change = function (goods) {
            $scope.stockChange = {};
            var stock = {};
            BaseGoods.stock_change_by_sku(goods).then(function (response) {
                if (response.data.status == 1) {
                    var stock_stream = response.data.data.data;  //data中对应的记录
                    //库存报表数据
                    var stock_data = response.data.data.report;  //report里面包含所有时间对应的库存数量

                    var days = Object.keys(stock_stream).sort().reverse();  //所有的时间

                    $.each(days, function (i, day) {
                        var n = stock_stream[day];  //时间对应后面的记录
                        stock[day] = {};
                        var num;
                        $.each(n, function (index, data) {
                            stock[day][data.record_type] = (typeof stock[day][data.record_type] == "undefined") ? {} : stock[day][data.record_type];
                            switch (data.record_type) {
                                case "1":
                                    num = (typeof stock[day][data.record_type].stock_change_num == "undefined") ? 0 : stock[day][data.record_type].stock_change_num;
                                    stock[day][data.record_type] = {'stock_change_num': parseFloat(num) + parseFloat(data.stock_change_num)};
                                    break;
                                case "9":
                                    num = (typeof stock[day][data.record_type].stock_change_num === "undefined") ? 0 : stock[day][data.record_type].stock_change_num;
                                    stock[day][data.record_type] = {'stock_change_num': parseFloat(num) + parseFloat(data.stock_change_num)};
                                    break;
                                case "10":
                                    num = (typeof stock[day][data.record_type].stock_change_num === "undefined") ? 0 : stock[day][data.record_type].stock_change_num;
                                    stock[day][data.record_type] = {'stock_change_num': parseFloat(num) + parseFloat(data.stock_change_num)};
                                    break;
                                case "11":
                                    num = (typeof stock[day][data.record_type].stock_change_num === "undefined") ? 0 : stock[day][data.record_type].stock_change_num;
                                    stock[day][data.record_type] = {'stock_change_num': parseFloat(num) + parseFloat(data.stock_change_num)};
                                    break;
                                case "16":
                                    num = (typeof stock[day][data.record_type].stock_change_num == "undefined") ? 0 : stock[day][data.record_type].stock_change_num;
                                    stock[day][data.record_type] = {'stock_change_num': parseFloat(num) + parseFloat(data.stock_change_num)};
                                    break;
                            }
                        });
                        stock[day]['stockNum'] = stock_data[day]; //当天的在库库存数量
                    });
                    $scope.stockChange = stock;
                    $scope.days = days;         //所有的时间


                    //图表数据
                    var series_data = {'data': [], 'date': [], 'kucun': []};
                    series_data.date = Object.keys(stock_data).sort(); //时间排序


                    $.each(series_data.date, function (i, d) {
                        series_data.kucun.push(parseInt(stock_data[d]));
                    });

                    //查询并显示商品的在库库存堆积图
//	                if($scope.chart_cur == 1){
                    refresh_stock_chart_show(series_data);
//	                }
                } else {

//                  if($scope.chart_cur == 1){
                    //库存三十天变更记录清空
                    $scope.stockChange = {};
                    $scope.days = {};         //所有的时间
//                	    //图表数据
                    require(['echarts', 'echarts/chart/bar'],
                            function (ec) {
                                // 基于准备好的dom，初始化echarts图表
                                var chart_goods_stock = ec.init(document.getElementById('chart_goods_stock'));
                                var option = {};
                                option = {
                                    title: {text: $rootScope.language.TIP_REPORT_ECHARTS_KC},
                                    tooltip: {trigger: 'axis'},
                                    axisPointer: {// 坐标轴指示器，坐标轴触发有效
                                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                                    },
                                    legend: {data: [$rootScope.language.TIP_REPORT_ECHARTS_LENGD]},
                                    realtime: false,
                                    xAxis: [
                                        {
                                            type: 'category',
                                            data: {}
                                        }
                                    ],
                                    yAxis: [
                                        {
                                            type: 'value'
                                        }
                                    ],
                                    series: [
                                        {
                                            name: $rootScope.language.TIP_REPORT_ECHARTS_KC,
                                            type: 'bar',
                                            stack: $rootScope.language.TIPS_NUM,
                                            data: {},
                                            markLine: {
                                                data: [
                                                    {type: 'average', name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD_AVERAGE}
                                                ]
                                            }
                                        }
                                    ]
                                };
                                // 为echarts对象加载数据
                                chart_goods_stock.setOption({});
                            });
//                  }

                }
            });
        };

        //刷新堆积图报表显示
        var refresh_stock_chart_show = function (data) {

            //加载库存数量堆积图 ++++++++++++++++++++++++++++++++++++++++
            require(['echarts', 'echarts/chart/bar'],
                    function (ec) {
                        // 基于准备好的dom，初始化echarts图表
                        var chart_goods_stock = ec.init(document.getElementById('chart_goods_stock'));
                        var option = {};
                        option = {
                            title: {text: $rootScope.language.TIP_REPORT_ECHARTS_KC},
                            tooltip: {trigger: 'axis'},
                            axisPointer: {// 坐标轴指示器，坐标轴触发有效
                                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                            },
                            legend: {data: [$rootScope.language.TIP_REPORT_ECHARTS_LENGD]},
                            realtime: false,
                            xAxis: [
                                {
                                    type: 'category',
                                    data: data.date
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value'
                                }
                            ],
                            series: [
                                {
                                    name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD,
                                    type: 'bar',
                                    stack: $rootScope.language.TIPS_RECEIPT_NUM,
                                    data: data.kucun,
                                    markLine: {
                                        data: [
                                            {type: 'average', name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD_AVERAGE}
                                        ]
                                    }
                                }
                            ]
                        };
                        // 为echarts对象加载数据
                        chart_goods_stock.setOption(option);
                    });
        };

    }];
//库存帐分析
var KczfxCtrl = ['$q' ,'$scope', '$rootScope', 'BaseGoods','timeStamp2String','Print','dbGetOne','ngDialog','$timeout','printWaitMsg','closePrintWaitMsg', function ($q, $scope, $rootScope, BaseGoods,timeStamp2String,Print,dbGetOne,ngDialog,$timeout,printWaitMsg,closePrintWaitMsg) {
        $scope.curr = 'kczfx curr';
        $scope.skunum_type = 0;
        //获取库存信息
        $scope.list = {};
        var length = 50;   //每五十条获取一次
        var totalCounts;   //商品的总数量
        $scope.goodSearch = function (goodCode) {
            if (typeof goodCode == 'undefined')
            {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_RIGHT_GOODS_CODE})
            } else {
                //baison_app.api.alert({msg:goodCode,title:'goodCode'});
                BaseGoods.get_stock_list(goodCode).then(function (response) {
                    if (response.data.data.data.status == 1) {
                        if (response.data.data.data.data.length != 1) {
                            baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_RIGHT_GOODS_CODE_CHECK});
                        } else {
                            $scope.list = response.data.data.data.data;
							if (response.price[0]) {
								$scope.list[0].SkuVipPrice = response.price[0].SkuVipPrice;
								$scope.list[0].SkuPrice = response.price[0].SkuPrice;
								$scope.list[0].SkuChenlie = response.price[0].SkuChenlie;
							}

                            getSkuNum();
                        }
                    } else {
                        baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS});
                    }
                });
            }
        };

//      //获取商品的总记录数
//       var getTotalCounts = function(){
//       	BaseGoods.get_all_len_skus().then(function(response){
//           	 totalCounts = response[0].num;
//           });
//       }
//       
//         getTotalCounts(); 

        //商品库存查询列表显示
        $scope.spkccxlb_show = true;
        $scope.spkccxlb = function () {
            if ($scope.spkccxlb_show) {
                $scope.spkccxlb_show = false;
            } else {
                $scope.spkccxlb_show = true;
            }
        };

        //在库库存列表显示
        $scope.zkkclb_show = true;
        $scope.zkkclb = function () {
            if ($scope.zkkclb_show) {
                $scope.zkkclb_show = false;
            } else {
                $scope.zkkclb_show = true;
            }
        };
        //获取小票商品明细信息
        var get_goods_detail_infos = function(detail){
            var deferred = $q.defer();
            var promise = deferred.promise;
            detail.forEach(function(n,i){
                deferred[i] = $q.defer();
                promise[i] = deferred[i].promise;
                dbGetOne('select GoodsCode,SortCode,CategoryCode,weight,unit_name from PosGoods where GoodsCode="' + n.GoodsCode + '" order by CategoryCode desc, SortCode desc').then(function(ret){
                    n.weight = ret.weight;
                    n.unit_name = ret.unit_name;
                    n.category_code = ret.CategoryCode;
                    n.goods_code = ret.GoodsCode;
                    n.sort_code = ret.SortCode;
                    deferred[i].resolve('success');
                });
               
            });
            return $q.all(promise);
        };
        
        //获取小票信息
		var stock_getinfo = function (stock_detail) {
			var record = {};
			var configData = $api.getStorage('configData');
			var printData = configData.printData;
			var shop_addr = '';
			var shop_tel = '';
			var web_site = '';
			if (printData != undefined) {
				shop_addr = printData['addr'];
				shop_tel = printData['tel'];
				web_site = printData['web_site'];
			}

			record.check_code = '';
			record.check_time = timeStamp2String(0, 'datetime');
			record.stock_detail = stock_detail;
			record.shop_name = $rootScope.current_shop.ShopName;
			record.user_code = $rootScope.user.UserCode;
			record.user_name = $rootScope.user.UserName;
			record.brand_name = $rootScope.company_info.brand_name;
			record.shop_addr = shop_addr;
			record.shop_tel = shop_tel;
			record.web_site = $rootScope.company_info.website;
			//库存排序
			record.stock_detail.sort(function(a,b){
				if(a.category_code > b.category_code){
					return -1;
				}else if(a.category_code == b.category_code){
					if(a.sort_code > b.sort_code){
						return -1;
					}else if(a.sort_code == b.sort_code){
						if(a.goods_code > b.goods_code){
							return -1;
						}else if(a.goods_code == b.goods_code){
							return 0;
						}else{
							return 1;
						}
					}else{
						return 1;
					}
				}else{
					return 1;
				}
			});
			return record;
		};

        //打印盘点数据
        $scope.to_print = function () {
            //add by liuwei on 20170527 打印控制
			var wait_data = printWaitMsg();
            BaseGoods.get_all_good_by_SkuNum(2, 0, length).then(function (ret) {
	             get_goods_detail_infos(ret).then(function(){
                    var stock = stock_getinfo(ret);
                    Print.stock_print('', stock).then(function(){
						closePrintWaitMsg("success",wait_data,stock.stock_detail.length);
					}, function(){
						closePrintWaitMsg("fail",wait_data);
					});
                });
            });
 
        };
        
        

        //获取本地库存不等于0的数量
        var getSkuNum = function () {
            $scope.skuNumList = [];
            BaseGoods.get_all_good_by_SkuNum($scope.skunum_type, 0, length).then(function (ret) {
	            if (ret.length == 0) {
                    $scope.is_show = "";
                    $scope.skuNumList = [];
                } else {
                    //type:用来区分全部显示和现有库存的下一页按钮显示隐藏
                    $scope.type = "true";
                    $scope.is_show = "true";
                    $scope.skuNumList = ret;
                }
            });
        };
        getSkuNum();

        $scope.ShowSkuNum = function () {
            getSkuNum();
        };
        //滑动事件加载锁========================================
        //往下点击获取更多
        $scope.scoll = {};
        //滚动加载器
        $scope.scoll.busy = false;
        $scope.scoll.nextpage = function () {
            if ($scope.scoll.busy) {
                return;
            }
            baison_app.api.toast({
                msg: $rootScope.language.COMMON_LOADING
            });
            $scope.scoll.busy = true;
            BaseGoods.get_all_good_by_SkuNum($scope.skunum_type,length, 50).then(function (ret) {
                length = length + 50;
//              //现在获取的sku数量与所有sku数量进行比较，若小于总数量，则往下获取
//              if(length < totalCounts){	
				if($scope.skunum_type == 0){
					if (ret.length > 0) {
	                    $.each(ret, function (i, n) {
	                        $scope.skuNumList.push(n);
	                    });
	                    $scope.scoll.busy = false;
	                } else {
	                    baison_app.api.toast({
	                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
	                    });
	                    $scope.type = "true";
	                    $scope.is_show = "";
	                    $scope.scoll.busy = false;
	                }
				}
				if($scope.skunum_type == 1){
					if (ret.length > 0) {
	                    $.each(ret, function (i, n) {
	                        $scope.skuNumList.push(n);
	                    });
	                    $scope.scoll.busy = false;
	                } else {
	                    baison_app.api.toast({
	                        msg: $rootScope.language.TIPS_CUNHUO_MESSAGE
	                    });
	                    $scope.type = "";
	                    $scope.is_show = "";
	                    $scope.scoll.busy = false;
	                }
				}
                
//              }else{
//              	baison_app.api.toast({
//	                        msg: '没有更多数据'
//	                    });
//	                    $scope.showTest = 1;
//	                    $scope.is_show = "";
//              }
            });
        };

    }];
//进销存分析
var JxcfxCtrl = ['$scope', '$rootScope', 'changeDate', 'Report', 'ngDialog', 'timeStamp2String', function ($scope, $rootScope, changeDate, Report, ngDialog, timeStamp2String) {
        $scope.curr = 'jxcfx curr';
        var window_id = 0;
        var pageNum = 1;
        var countPage = 1;
        $scope.buttonMore = 0;
        $scope.persBox = true;  //显示列默认隐藏
        $scope.check = {};  //显示列选中效果
        $scope.scoll = {};
        $scope.goodsStock = [];


//        $scope.columns = {
//            '商品代码': {'name': '商品代码'},
//            '商品名称': {'name': '商品名称'},
//            '期初数量': {'name': '期初数量'},
//            '期初金额': {'name': '期初金额false'},
//            '配货入': {'name': '配货入'},
//            '配货入金额': {'name': '配货入金额false'},
//            '零售出': {'name': '零售出'},
//            '零售出金额': {'name': '零售出金额false'},
//            '零售退': {'name': '零售退'},
//            '零售退金额': {'name': '零售退金额false'},
//            '移仓入': {'name': '移仓入'},
//            '移仓入金额': {'name': '移仓入金额false'},
//            '移仓出': {'name': '移仓出'},
//            '移仓出金额': {'name': '移仓出金额false'},
//            '期末数量': {'name': '期末数量'},
//            '期末金额': {'name': '期末金额false'},
//            '标准价': {'name': '标准价false'},
//            '仓库金额': {'name': '仓库金额false'}};

//        $scope.cols_list = [
//            {'name': '商品代码', 'initial': 'true'},
//            {'name': '商品名称', 'initial': 'true'},
//            {'name': '期初数量', 'initial': 'true'},
//            {'name': '期初金额', 'initial': 'false'},
//            {'name': '配货入', 'initial': 'true'},
//            {'name': '配货入金额', 'initial': 'false'},
//            {'name': '零售出', 'initial': 'true'},
//            {'name': '零售出金额', 'initial': 'false'},
//            {'name': '零售退', 'initial': 'true'},
//            {'name': '零售退金额', 'initial': 'false'},
//            {'name': '移仓入', 'initial': 'true'},
//            {'name': '移仓入金额', 'initial': 'false'},
//            {'name': '移仓出', 'initial': 'true'},
//            {'name': '移仓出金额', 'initial': 'false'},
//            {'name': '期末数量', 'initial': 'true'},
//            {'name': '期末金额', 'initial': 'false'},
//            {'name': '标准价', 'initial': 'false'},
//            {'name': '仓库金额', 'initial': 'false'}];
        $scope.columns = [];
        $scope.columns[$rootScope.language.TIPS_REPORT_GOODS_CODE] = {'name': $rootScope.language.TIPS_REPORT_GOODS_CODE};
        $scope.columns[$rootScope.language.TIPS_REPORT_GOODS_NAME] = {'name': $rootScope.language.TIPS_REPORT_GOODS_NAME};
        $scope.columns[$rootScope.language.TIPS_REPORT_INITAL_NUM] = {'name': $rootScope.language.TIPS_REPORT_INITAL_NUM};
        $scope.columns[$rootScope.language.TIPS_REPORT_INITAL_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_ACLLOCAT_CARGO_IN] = {'name': $rootScope.language.TIPS_REPORT_ACLLOCAT_CARGO_IN};
        $scope.columns[$rootScope.language.TIPS_REPORT_ACLLOCAT_CARGO_IN_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETURN_OUT_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETURN_OUT_NUM] = {'name': $rootScope.language.TIPS_REPORT_RETURN_OUT_NUM};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETAIL_OUT] = {'name': $rootScope.language.TIPS_REPORT_RETAIL_OUT};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETAIL_OUT_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETAIL_RETURN] = {'name': $rootScope.language.TIPS_REPORT_RETAIL_RETURN};
        $scope.columns[$rootScope.language.TIPS_REPORT_RETAIL_RETURN_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_MOVE_STORE_IN] = {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_IN};
        $scope.columns[$rootScope.language.TIPS_REPORT_MOVE_STORE_IN_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_MOVE_STORE_OUT] = {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_OUT};
        $scope.columns[$rootScope.language.TIPS_REPORT_MOVE_STORE_OUT_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_FINAL_NUM] = {'name': $rootScope.language.TIPS_REPORT_FINAL_NUM};
        $scope.columns[$rootScope.language.TIPS_REPORT_ADJUST_NUM] = {'name': $rootScope.language.TIPS_REPORT_ADJUST_NUM};
        $scope.columns[$rootScope.language.TIPS_REPORT_ADJUST_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_FINAL_MONEY] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_NORMAL_PRICE] = {'name': ''};
        $scope.columns[$rootScope.language.TIPS_REPORT_ENTREPOT_MONEY] = {'name': ''};

		$scope.cols_list = [
	      {'name': $rootScope.language.TIPS_REPORT_GOODS_CODE, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_GOODS_NAME, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_INITAL_NUM, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_INITAL_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_ACLLOCAT_CARGO_IN, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_ACLLOCAT_CARGO_IN_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_RETURN_OUT_MONEY, 'initial': true},
	      {'name': $rootScope.language.TIPS_REPORT_RETURN_OUT_NUM, 'initial': false},
	      {'name': $rootScope.language.TIPS_REPORT_RETAIL_OUT, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_RETAIL_OUT_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_RETAIL_RETURN, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_RETAIL_RETURN_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_IN, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_IN_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_OUT, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_MOVE_STORE_OUT_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_FINAL_NUM, 'initial': 'true'},
	      {'name': $rootScope.language.TIPS_REPORT_FINAL_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_NORMAL_PRICE, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_ENTREPOT_MONEY, 'initial': 'false'},
	      {'name': $rootScope.language.TIPS_REPORT_ADJUST_NUM, 'initial': true},
	      {'name': $rootScope.language.TIPS_REPORT_ADJUST_MONEY, 'initial': false}
		];


        //判断联网状态
        var connectionType = baison_app.api.connectionType;
        if (connectionType == 'none') {
            baison_app.api.toast({msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
            return;
        }

        //查询按钮（调出弹窗）
        $scope.search = function () {
            //查询
            $scope.filter = {};
            $scope.filter.record_time_start = changeDate(30, 1);
            $scope.filter.record_time_end = changeDate(1);
            $scope.filter.goods_code = '';
            $scope.filter.categorys = {};
            $scope.filter.categorys.category_code = '';
            $scope.filter.sorts = {};
            $scope.filter.sorts.sort_code = '';
            $scope.filter.pageNum = pageNum;
            $scope.filter.countPage = countPage;
            window_id = ngDialog.open({closeByDocument: false,
                template: './html/report/jxcfx/jxc_search.html',
                disableAnimation: true,
                scope: $scope,
                trapFocus: false,
                controller: [function () {
                    //获取所有大小分类信息
                    var get_goods_types = function(){
                        Report.get_goods_types().then(function(ret){
                            $scope.cates = ret.cates;
                            $scope.sorts = ret.sorts;
                        });
                    };
                    get_goods_types();
                }]
            });
        };

        //查询处理逻辑
        var search_jxc_deal = function(filter){
            if (pageNum > countPage) {
                baison_app.api.toast({msg: $rootScope.language.TIP_ORDER_RECEIPT_DATA});
                return;
            }

            //$scope.goodsStock = [];
            Report.get_Jxc_total(filter).then(function (response) {
                if (response.data.status == 1) {
                    var data = response.data.data.data;
                    countPage = response.data.data.countPage;
                    if(countPage > pageNum){
                        $scope.buttonMore = 1;
                    }
                    //第一次加载 更新汇总信息
                    if (pageNum == 1) {
                        $scope.qichu_num = data.total.total_start_total_inv_num;
                        $scope.qichu_money = data.total.total_start_total_inv_money;
                        $scope.qimo_num = data.total.total_end_total_inv_num;
                        $scope.qimo_money = data.total.total_end_total_inv_money;
                    }
                    delete data.total;
                    $.each(data, function (i, n) {
                        $scope.goodsStock.push({
                            'goods_code': n.goods_code,
                            'goods_name': n.goods_name,
                            'start_total_inv_num': n.start_total_inv_num,
                            'start_total_inv_money': n.start_total_inv_money,
                            'dim_allocate_in_num': n.dim_allocate_in_num,
                            'dim_allocate_in_money': n.dim_allocate_in_money,
                            'dim_return_out_money': n.dim_return_out_money,
                            'dim_return_out_num': n.dim_return_out_num,
                            'rbm_sale_num': n.rbm_sale_num,
                            'rbm_sale_money': n.rbm_sale_money,
                            'rbm_return_num': n.rbm_return_num,
                            'rbm_return_money': n.rbm_return_money,
                            'stm_store_shift_in_num': n.stm_store_shift_in_num,
                            'stm_store_shift_in_money': n.stm_store_shift_in_money,
                            'stm_store_shift_out_num': n.stm_store_shift_out_num,
                            'stm_store_shift_out_money': n.stm_store_shift_out_money,
                            'stm_stock_adjust_num': n.stm_stock_adjust_num,
                            'stm_stock_adjust_money': n.stm_stock_adjust_money,
                            'end_total_inv_num': n.end_total_inv_num,
                            'store_money': n.store_money,
                            'sell_price': n.sell_price,
                            'end_total_inv_money': n.end_total_inv_money
                        });

                    });
                }
            });
        };

        //弹窗处理====================================
        $scope.btn_search = function (filter) {
            search_jxc_deal(filter);
            ngDialog.close(window_id);
        };
        //更多
        $scope.scoll.nextpage = function(){
            $scope.filter.pageNum++;
            search_jxc_deal($scope.filter);
            
        };
        //重置操作
        $scope.reset = function (filter) {
            $scope.filter.goods_code = '';
            $scope.filter.category_code = '';
        };
        //显示列操作
        $scope.columnToggle = function () {
            $scope.persBox = !$scope.persBox;
            if ($scope.navBox && $scope.persBox) {
                $scope.shade = true;
            } else {
                $scope.shade = false;
            }
            $scope.goods = true;
            if ($scope.persBox) {
                $scope.persAnimate = ""
            } else {
                $scope.persAnimate = "active"
            }
//
//          return false
        };
        $scope.columnClose = function () {
            $scope.persBox = true;
            if ($scope.navBox && $scope.persBox) {
                $scope.shade = true;
            }
            if ($scope.persBox) {
                $scope.persAnimate = ""
            } else {
                $scope.persAnimate = "active"
            }
        };

        $scope.chooseOne = function (index, check) {         
            if (check == true) {//选中
                $scope.columns[index] = {"name": index};
            } else {
                delete $scope.columns[index];
                //取消选中
                delete $scope.check[index];
            }

        };

    }];
//会员分析
var ArfxCtrl = ['$scope', '$rootScope', 'PosUser', 'timeStamp2String', function ($scope, $rootScope, PosUser, timeStamp2String) {
        $scope.curr = 'arfx curr';
        $scope.buttonCurr = 0;

        //数据情况查询
        $scope.search_data = function (filter) {
            $scope.data = {};
            if (typeof filter == 'undefined') {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_RIGHT_USER_CODE});
            } else {
                if (typeof filter.guideCode == 'undefined') {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_RIGHT_USER_CODE});
                } else if (typeof filter.time_start == 'undefined' || typeof filter.time_end == 'undefined') {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME});
                } else if (filter.time_start > filter.time_end) {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT});
                    return;
                } else {
                    $scope.data.time_start = timeStamp2String(filter.time_start, 'datetime');
                    $scope.data.time_end = timeStamp2String(filter.time_end, 'date');
                    $scope.data.time_end = $scope.data.time_end.concat(" ");
                    $scope.data.time_end = $scope.data.time_end.concat("23:59:59");
                    $scope.data.time_end = timeStamp2String($scope.data.time_end, 'datetime');
                    $scope.data.guideCode = filter.guideCode;
                    PosUser.get_user_performance($scope.data).then(function (ret) {
                        if (ret.data.status = '1') {
                            if (ret.data.data == []) {
                                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIPS_CUNHUO_SEARCH_GOODS});
                            }
                            $scope.guidePerformance = ret.data.data[0];
                        } else {
                            baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language[ret.data.message]});
                        }
                    });
                }
            }
        };

        var echar_single = function (data, title) {
            require(['echarts', 'echarts/chart/bar'],
                    function (ec) {
                        // 基于准备好的dom，初始化echarts图表
                        var chart_goods_stock = ec.init(document.getElementById(title.id));
                        var option = {};
                        option = {
                            title: {text: title.headline},
                            tooltip: {},
                            axisPointer: {// 坐标轴指示器，坐标轴触发有效
                                type: 'shadow'        // ，可选默认为直线为：'line' | 'shadow'
                            },
                            legend: {
                                data: [title.cutline]
                            },
                            realtime: false,
                            xAxis: [
                                {
                                    type: 'category',
                                    data: data.date
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value'
                                }
                            ],
                            series: [
                                {
                                    name: title.cutline,
                                    type: 'bar',
                                    data: data.kucun,
                                    markLine: {
                                        data: [
                                            {type: 'average', name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD_AVERAGE}
                                        ]
                                    }
                                }
                            ]
                        };
                        // 为echarts对象加载数据
                        chart_goods_stock.setOption(option);
                    });
        };
        var echarts_double = function (data1, data2, title) {
            require(['echarts', 'echarts/chart/bar'],
                    function (ec) {
                        // 基于准备好的dom，初始化echarts图表
                        var chart_goods_stock = ec.init(document.getElementById(title.id));
                        var option = {};
                        option = {
                            title: {text: title.headline},
                            tooltip: {},
                            axisPointer: {// 坐标轴指示器，坐标轴触发有效
                                type: 'shadow'        // ，可选默认为直线为：'line' | 'shadow'
                            },
                            legend: {
                                data: [title.cutline1, title.cutline2]
                            },
                            realtime: false,
                            xAxis: [
                                {
                                    type: 'category',
                                    data: data1.date
                                }
                            ],
                            yAxis: [
                                {
                                    type: 'value'
                                }
                            ],
                            series: [
                                {
                                    name: title.cutline1,
                                    type: 'bar',
                                    data: data1.kucun,
                                    markLine: {
                                        data: [
                                            {type: 'average', name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD_AVERAGE}
                                        ]
                                    }
                                },
                                {
                                    name: title.cutline2,
                                    type: 'bar',
                                    data: data2.kucun,
                                    markLine: {
                                        data: [
                                            {type: 'average', name: $rootScope.language.TIP_REPORT_ECHARTS_LENGD_AVERAGE}
                                        ]
                                    }
                                }
                            ]
                        };
                        // 为echarts对象加载数据
                        chart_goods_stock.setOption(option);
                    });
        };



        //会员增长量年度分析
        $scope.memberIncrease = function () {
            $scope.buttonCurr = 0;
            var increaseYearNow = {
                "kucun": [19, 27, 51, 61, 24, 17, 47, 54],
                "date": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
            };
            var increaseYearPast = {
                "kucun": [15, 37, 11, 21, 44, 37, 17, 34, 32, 52, 57, 62],
                "date": ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
            };
            var title = {
                headline: "",
                cutline1: $rootScope.language.TIP_REPORT_MEMBER_INCREASE_THIS,
                cutline2: $rootScope.language.TIP_REPORT_MEMBER_INCREASE_LAST,
                id: 'chart_goods_stock'
            };
            echarts_double(increaseYearNow, increaseYearPast, title);
        };
        $scope.memberIncrease();
        //会员客单价分析
        $scope.memberPrice = function () {
            $scope.buttonCurr = 1;

            $scope.customerPer = function () {
                var titleCustomerPer = {
                    headline: $rootScope.language.TIP_REPORT_MEMBER_MONEY,
                    cutline: $rootScope.language.TIP_REPORT_MEMBER_NUM,
                    id: 'chart_goods_stock1'
                };
                var customerPer = {
                    "kucun": [19, 27, 51, 61, 24, 17, 47, 54, 22, 32, 27, 42],
                    "date": ["0~50", "50~100", "100~150", "150~200", "150~250", "250~300", "300~350", "350~400", "400~450", "450~500", "500~550", "550以上"]
                };
                echar_single(customerPer, titleCustomerPer);
            };
            $scope.associateRate = function () {
                var associateRate = {
                    "kucun": [8.9, 2.7, 1.1, 9.1, 7.4, 9.7, 4.7, 5.4, 2.2, 3.2, 2.7, 4.2],
                    "date": ["2015-12", "2015-11", "2015-10", "2015-09", "2015-08", "2015-07", "2015-06", "2015-05", "2015-04", "2015-03", "2015-02", "2015-01"]
                };
                var titleAssociateRate = {
                    headline: $rootScope.language.TIP_REPORT_SALE_LIAN,
                    cutline: $rootScope.language.TIP_REPORT_SALE_LIAN_RATE,
                    id: 'chart_goods_stock2'
                };
                echar_single(associateRate, titleAssociateRate);
            };
            $scope.customerPer();
            $scope.associateRate();
        };

        //数据情况折叠显示
        $scope.sjqk_show = true;
        $scope.sjqk = function () {
            if ($scope.sjqk_show) {
                $scope.sjqk_show = false;
            } else {
                $scope.sjqk_show = true;
            }
        };
        //客单发布图折叠显示
        $scope.kdfb_show = true;
        $scope.kdfb = function () {
            if ($scope.kdfb_show) {
                $scope.kdfb_show = false;
            } else {
                $scope.kdfb_show = true;
            }
        };
        //连带率分布图折叠显示
        $scope.ldlfb_show = true;
        $scope.ldlfb = function () {
            if ($scope.ldlfb_show) {
                $scope.ldlfb_show = false;
            } else {
                $scope.ldlfb_show = true;
            }
        };

        //会员礼品领用表
        $scope.memberPreasent = function () {
            $scope.buttonCurr = 2;

//          $rootScope.purviewCheck();

        };

        //会员生日报表
        $scope.memberBirthday = function () {
            $scope.buttonCurr = 3;

        };
    }];
//热销商品排行
var RxphCtrl = ['$scope', '$rootScope', 'ShopSetCheck', 'ReceiptRecord', 'timeStamp2String', function ($scope, $rootScope, ShopSetCheck, ReceiptRecord, timeStamp2String) {
        ShopSetCheck();
        $scope.curr = 'rxph curr';
        var total_num = 0;
        var total_money = 0;
        var time = 0;
        var search_type = 0; //0为 销量 1为 金额
        var goods = [];
        var day = 1;
        var rxph_init = function () {
            $scope.day_cur = 1;
            $scope.week_cur = 0;
            $scope.month_cur = 0;
            $scope.data_list = [];
            $scope.num_cur = 1;
            $scope.money_cur = 0;
            search_type = 0;
            $scope.th_num_name = $rootScope.language.TIP_REPORT_SALE_NUM;
            $scope.th_pre_name = $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT;
        };

        var reset = function () {

            $scope.data_list = [];
            goods = {
                label: [],
                value: []
            };
            total_num = 0;
            total_money = 0;
        };
        //获取页签数据
        var getdatalist = function (type) {
            ReceiptRecord.get_hot_goods(time, type).then(function (ret) {
                reset();
                $.each(ret, function (k, v) {
                    total_num = Number(total_num) + Number(v.num);
                    total_money = Number(total_money) + Number(v.money);

                });

                if (ret.length > 0) {
                    $.each(ret, function (i, n) {
                        var data = {};
                        data['goods'] = n.goods_name;
                        data['sku'] = n.sku;
                        data['num'] = (parseInt(n.num));
                        data['money'] = (parseFloat(n.money)).toFixed(2);
                        if (search_type) {
                            data['rate'] = parseFloat(n.money / total_money).toFixed(2);
                            goods.value.push(n.money);
                            $scope.th_num_name = $rootScope.language.TIP_REPORT_SALE_MONEY;
                            $scope.th_pre_name = $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT;
                        } else {
                            data['rate'] = (parseFloat(n.num / total_num)).toFixed(2);
                            goods.value.push(n.num);

                            $scope.th_num_name = $rootScope.language.TIP_REPORT_SALE_NUM;
                            $scope.th_pre_name = $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT;
                        }
                        goods.label.push(n.goods_name);
                        $scope.data_list.push(data);
                    });
                    reportbar();
                } else {
                    var err_title = '';
                    if (search_type) {
                        err_title = $rootScope.language.TIP_REPORT_SALE_MONEY;
                    } else {
                        err_title = $rootScope.language.TIP_REPORT_SALE_NUM;
                    }
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_SALE_HOT});
                    reportbar();
                }
            });
        };

        var getdatalist_bytime = function (type) {
            if (typeof $scope.start_time == 'undefined' || typeof $scope.end_time == 'undefined') {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME});
                return;
            }
            var s_start = $scope.start_time.toString();
            var s_end = $scope.end_time.toString();
            var start_time = new Date(s_start);
            var s_start_time = start_time.getTime();
            var end_time = new Date(s_end);
            var s_end_time = end_time.getTime();
            var start = timeStamp2String(s_start_time, 'datetime');
            var end = timeStamp2String(s_end_time, 'datetime');
            ReceiptRecord.get_hot_goods_by_time(start, end, type).then(function (ret) {
                reset();
                $.each(ret, function (k, v) {
                    total_num = Number(total_num) + Number(v.num);
                    total_money = Number(total_money) + Number(v.money);
                });
                if (ret.length > 0) {
                    $.each(ret, function (i, n) {
                        var data = {};
                        data['goods'] = n.goods_name;
                        data['sku'] = n.sku;
                        data['num'] = (parseInt(n.num));
                        data['money'] = (parseFloat(n.money)).toFixed(2);
                        if (search_type) {
                            data['rate'] = parseFloat(n.money / total_money).toFixed(2);
                            goods.value.push(n.money);
                            $scope.th_num_name = $rootScope.language.TIP_REPORT_SALE_MONEY;
                            $scope.th_pre_name = $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT;
                        } else {
                            data['rate'] = (parseFloat(n.num / total_num)).toFixed(2);
                            goods.value.push(n.num);

                            $scope.th_num_name = $rootScope.language.TIP_REPORT_SALE_NUM;
                            $scope.th_pre_name = $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT;
                        }

                        $scope.data_list.push(data);
                        goods.label.push(n.goods_name);
                    });
                    reportbar();

                } else {
                    var err_title = '';
                    if (search_type) {
                        err_title = $rootScope.language.TIP_REPORT_SALE_MONEY;
                    } else {
                        err_title = $rootScope.language.TIP_REPORT_SALE_NUM;
                    }
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_SALE_HOT});
                    reportbar();
                }

            });
        };
        //当天页签
        $scope.tab_day_list = function () {
            $scope.day_cur = 1;
            $scope.week_cur = 0;
            $scope.month_cur = 0;
            time = timeStamp2String(0, 'date');
            day = 1;
            if (search_type) {
                getdatalist('money');
            } else {
                getdatalist('num');
            }

        };

        //本周页签
        $scope.tab_week_list = function () {
            $scope.day_cur = 0;
            $scope.week_cur = 1;
            $scope.month_cur = 0;
            var now = new Date(); //当前日期   
            var nowDayOfWeek = now.getDay(); //今天本周的第几天  
            nowDayOfWeek = nowDayOfWeek == 0 ? 7 : nowDayOfWeek;
            var s_time = now.getTime() - (nowDayOfWeek - 1) * 1000 * 60 * 60 * 24;
            time = timeStamp2String(s_time, 'date');
            day = 7;
            if (search_type) {
                getdatalist('money');
            } else {
                getdatalist('num');
            }

        };
        //本月页签
        $scope.tab_month_list = function () {
            $scope.day_cur = 0;
            $scope.week_cur = 0;
            $scope.month_cur = 1;
            var myDate = new Date();
            var thisyear = myDate.getFullYear();
            var thismonth = myDate.getMonth() + 1;
            var s_time = thisyear + "-" + thismonth + "-1";
            time = timeStamp2String(s_time, 'date');
            day = 30;
            if (search_type) {
                getdatalist('money');
            } else {
                getdatalist('num');
            }
        };
        //按销量页签
        $scope.tab_num_list = function () {
            $scope.num_cur = 1;
            $scope.money_cur = 0;
            search_type = 0;

            getdatalist('num');
        };
        //按金额页签
        $scope.tab_money_list = function () {
            $scope.num_cur = 0;
            $scope.money_cur = 1;
            search_type = 1;

            getdatalist('money');
        };
        //日期查询
        $scope.btn_search = function () {
            if (search_type) {
                getdatalist_bytime('money');
            } else {
                getdatalist_bytime('num');
            }
        };
        //获取页签饼状图
        var reportbar = function () {
            var title = {1: $rootScope.language.TIP_REPORT_SALE_TODAY, 7: $rootScope.language.TIP_REPORT_SALE_WEEK, 30: $rootScope.language.TIP_REPORT_SALE_MONTH};
            var text = $rootScope.language.TIP_REPORT_SALE_NUM;
            if (search_type) {
                text = $rootScope.language.TIP_REPORT_SALE_NUM_MONEY;
            }
            rxph_bar(day, title, text, goods);
        };
        rxph_init();
        //默认当天
        $scope.tab_day_list();

    }];
//导购业绩分析
var DgyjCtrl = ['$scope', '$rootScope', '$q','ShopSetCheck', 'ReceiptRecord', 'timeStamp2String', 'VIP',function ($scope, $rootScope,$q, ShopSetCheck, ReceiptRecord, timeStamp2String,VIP) {
        ShopSetCheck();
        $scope.curr = 'dgyj curr';
        var total_num = 0;
        var total_money = 0;
        var time = 0;
        $scope.filter = {};
        $scope.filter.start_time = '';
        $scope.filter.end_time = '';
        var search_type_bar = 0; //0为 销量 1为 金额 
        var search_type_pie = 0;//0为销量占比 1金额占比
        var goods_bar = {
            label: [],
            value: []
        };
        var goods_pie = {
            label: [],
            value: []
        };
        //业务小结列表
        $scope.sales_list = [];
        
        var day = 1;
        var dgyj_init = function () {
            $scope.dayd_cur = 1;
            $scope.weekd_cur = 0;
            $scope.monthd_cur = 0;
            $scope.numd_cur = 1;
            $scope.moneyd_cur = 0;
            $scope.numpred_cur = 1;
            $scope.moneypred_cur = 0;
            search_type_bar = 0;
            search_type_pie = 0;

        };

        var reset = function () {
            goods_bar = {
                label: [],
                value: []
            };
            goods_pie = {
                label: [],
                value: []
            };
            total_num = 0;
            total_money = 0;
        };
        //计算获取总计信息
        var get_total_sales_data = function(ret){    
            var total_sales_info = {};
            total_sales_info.daogou_name = '总计';
            total_sales_info.goods_num = 0;
            total_sales_info.real_pay_money = 0;
            total_sales_info.vip_pay_money = 0;
            total_sales_info.add_vip_num = 0;
            total_sales_info.record_num = 0;
            $.each(ret,function(i,n){
                total_sales_info.goods_num = parseInt(total_sales_info.goods_num)+parseInt(n.goods_num);
                total_sales_info.real_pay_money = parseFloat(total_sales_info.real_pay_money)+parseFloat(n.real_pay_money);
                total_sales_info.vip_pay_money = parseFloat(total_sales_info.vip_pay_money) + parseFloat(n.vip_pay_money);
                total_sales_info.record_num = parseInt(total_sales_info.record_num)+parseInt(n.record_num);
                total_sales_info.add_vip_num = parseInt(total_sales_info.add_vip_num)+parseInt(n.add_vip_num);
            });
            total_sales_info.sales_rebate = parseFloat(total_sales_info.goods_num/total_sales_info.record_num).toFixed(2);
            total_sales_info.vip_pay_rebate = parseFloat((total_sales_info.vip_pay_money/(total_sales_info.real_pay_money==0?1:total_sales_info.real_pay_money))*100).toFixed(2)+'%';
            ret['zongji'] = total_sales_info;
        };
        
        
        var vip_num_list = {};
        //获取业务小结列表数据处理逻辑
        var get_get_sales_data_list_deal = function(ret,day,start,end){
            var deferred = {};
            var promise = {};
            $.each(ret,function(i,n){
                deferred[i] = $q.defer();
                promise[i] = deferred[i].promise;
                n.sales_rebate = parseFloat(n.goods_num/n.record_num).toFixed(2);
                n.vip_pay_rebate = parseFloat((n.vip_pay_money/(n.real_pay_money==0?1:n.real_pay_money))*100).toFixed(2)+'%';
                VIP.get_local_vip_list_by_time(i,day,start,end).then(function(vipnum){
                    vip_num_list[i] = parseInt(vipnum[0].num);// 新增会员数
                    deferred[i].resolve('success');
                });
            });
            return $q.all(promise);
        };
        
        //获取业务小结列表数据
        var get_sales_data_list = function(){
            //业务小结列表
            $scope.sales_list = [];
            baison_app.api.showProgress({
				text: '',
				title: $rootScope.language.TIPS_DATA_NOT_DOWN,
				modal: false
			});
            return ReceiptRecord.get_salesdata_by_daogou(time,'','').then(function(ret){
                baison_app.api.hideProgress();
                if(Object.keys(ret).length == 0){
                    return;
                }
                return get_get_sales_data_list_deal(ret,time,'','').then(function(){
                    $.each(ret,function(i,n){
                        n.add_vip_num = vip_num_list[i];
                    });
                    
                    //计算获取总计信息
                    get_total_sales_data(ret);
                    
                    
                    $scope.sales_list = ret;
                });
            }).catch(function(){
                $scope.sales_list = '';
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
            });
        };
        //获取业务小结列表数据根据时间段
        var get_sales_data_list_by_time = function(startTime, endTime){
            //业务小结列表
            $scope.sales_list = [];
            var s_start = startTime.toString();
            var s_end = endTime.toString();
            var start_time = new Date(s_start);
            var s_start_time = start_time.getTime();
            var end_time = new Date(s_end);
            var s_end_time = end_time.getTime();
            var start = timeStamp2String(s_start_time, 'datetime');
            var end = timeStamp2String(s_end_time, 'datetime');
            baison_app.api.showProgress({
				text: '',
				title: $rootScope.language.TIPS_DATA_NOT_DOWN,
				modal: false
			});
            return ReceiptRecord.get_salesdata_by_daogou('',start, end).then(function(ret){
                baison_app.api.hideProgress();
                if(Object.keys(ret).length == 0){
                    return;
                }
                return get_get_sales_data_list_deal(ret,'',start,end).then(function(){
                    $.each(ret,function(i,n){
                        n.add_vip_num = vip_num_list[i];
                    });
                    //计算获取总计信息
                    get_total_sales_data(ret);
                    $scope.sales_list = ret;
                });
            }).catch(function(){
                $scope.sales_list = '';
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
            });

        };
        
        //获取页签数据
        var getdatalist = function (type, err_title) {
            reset();
            var ret = $scope.sales_list;
            if(ret === ''){
				$scope.sales_list = [];
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                reportcharts();
                return;
            }
            if(Object.keys(ret).length == 0){
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_SALE_HOT});
                reportcharts();
                return;
            }
            $.each(ret, function (k, v) {
                if(v.daogou_name != "总计"){
                    total_num = Number(total_num) + Number(v.goods_num);
                    total_money = Number(total_money) + Number(v.real_pay_money);
                }
                
            });
            $.each(ret, function (i, n) {
                if(n.daogou_name != "总计"){
                    goods_bar.label.push(n.daogou_name);
                    //0为 销量 1为 金额 2为销量占比 3金额占比
                    if (search_type_bar == 0) {
                        goods_bar.value.push(n.goods_num);
                    } else {
                        goods_bar.value.push(n.real_pay_money);

                    }
                    goods_pie.label.push(n.daogou_name);
                    if (search_type_pie == 0) {
                        goods_pie.value.push({'value': parseFloat(n.goods_num / total_num).toFixed(2), 'name': n.daogou_name});

                    } else {
                        goods_pie.value.push({'value': parseFloat(n.real_pay_money / total_money).toFixed(2), 'name': n.daogou_name});

                    }
                }
                
            });
            reportcharts();
        };
        //根据时段 获取页签数据
        var getdatalist_bytime = function (startTime, endTime, type, err_title) {
            var s_start = startTime.toString();
            var s_end = endTime.toString();
            var start_time = new Date(s_start);
            var s_start_time = start_time.getTime();
            var end_time = new Date(s_end);
            var s_end_time = end_time.getTime();
            var start = timeStamp2String(s_start_time, 'datetime');
            var end = timeStamp2String(s_end_time, 'datetime');
            ReceiptRecord.get_cash_by_daogou_by_time(start, end, type).then(function (ret) {
                reset();
                if (ret.length > 0) {
                    $.each(ret, function (k, v) {
                        if(v.daogou_name != "总计"){
                            total_num = Number(total_num) + Number(v.goods_num);
                            total_money = Number(total_money) + Number(v.real_pay_money);
                        }

                    });
                    $.each(ret, function (i, n) {
                        if(n.daogou_name != '总计'){
                            goods_bar.label.push(n.UserName);
                            //0为 销量 1为 金额 2为销量占比 3金额占比
                            if (search_type_bar == 0) {
                                goods_bar.value.push(n.num);
                            } else {
                                goods_bar.value.push(n.money);

                            }
                            goods_pie.label.push(n.UserName);
                            if (search_type_pie == 0) {
                                goods_pie.value.push({'value': parseFloat(n.num / total_num).toFixed(2), 'name': n.UserName});

                            } else {
                                goods_pie.value.push({'value': parseFloat(n.money / total_money).toFixed(2), 'name': n.UserName});

                            }
                        }
                        
                    });
                    reportcharts();

                } else {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_SALE_HOT});
                    reportcharts();
                }

            });
        };
        //当天页签
        $scope.tab_dayd_list = function () {
            $scope.dayd_cur = 1;
            $scope.weekd_cur = 0;
            $scope.monthd_cur = 0;

            time = timeStamp2String(0, 'date');
            day = 1;
            get_sales_data_list().then(function(){
                if (search_type_bar == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY);
                }
                
                if (search_type_pie == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);
                }
            });
            
        };

        //本周页签
        $scope.tab_weekd_list = function () {
            $scope.dayd_cur = 0;
            $scope.weekd_cur = 1;
            $scope.monthd_cur = 0;
            var now = new Date(); //当前日期   
            var nowDayOfWeek = now.getDay(); //今天本周的第几天  
            nowDayOfWeek = nowDayOfWeek == 0 ? 7 : nowDayOfWeek;
            var s_time = now.getTime() - (nowDayOfWeek - 1) * 1000 * 60 * 60 * 24;
            time = timeStamp2String(s_time, 'date');
            day = 7;
            get_sales_data_list().then(function(){
                if (search_type_bar == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY);
                }
                if (search_type_pie == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);
                }
            });
            
        };
        //本月页签
        $scope.tab_monthd_list = function () {
            $scope.dayd_cur = 0;
            $scope.weekd_cur = 0;
            $scope.monthd_cur = 1;
            var myDate = new Date();
            var thisyear = myDate.getFullYear();
            var thismonth = myDate.getMonth() + 1;
            var s_time = thisyear + "-" + thismonth + "-1";
            time = timeStamp2String(s_time, 'date');
            day = 30;
            get_sales_data_list().then(function(){
                if (search_type_bar == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY);
                }
                if (search_type_pie == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);
                }
            });
            
        };
        //按销量页签
        $scope.tab_numd_list = function () {
            $scope.numd_cur = 1;
            $scope.moneyd_cur = 0;
            search_type_bar = 0;
            getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM);

        };
        //按金额页签
        $scope.tab_moneyd_list = function () {
            $scope.numd_cur = 0;
            $scope.moneyd_cur = 1;

            search_type_bar = 1;
            //type = 'money';
            getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY);
            reportcharts();

        };
        //按数量占比
        $scope.tab_numpred_list = function () {

            $scope.numpred_cur = 1;
            $scope.moneypred_cur = 0;
            search_type_pie = 0;
            getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);


        };
        //按金额占比
        $scope.tab_moneypred_list = function () {

            $scope.numpred_cur = 0;
            $scope.moneypred_cur = 1;
            search_type_pie = 1;
            getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
        };
        //日期查询
        $scope.btn_search = function () {
            if (!$scope.start_time || !$scope.end_time) {
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.TIP_REPORT_TIME});
                return;
            }
            console.log($scope.start_time);
            console.log($scope.end_time);
            get_sales_data_list_by_time($scope.start_time, $scope.end_time).then(function(){
                if (search_type_bar == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM);
                    //getdatalist_bytime(filter.start_time, filter.end_time, 'num', $rootScope.language.TIP_REPORT_SALE_NUM);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY);
                    //getdatalist_bytime(filter.start_time, filter.end_time, 'money', $rootScope.language.TIP_REPORT_SALE_MONEY);
                }
                if (search_type_pie == 0) {
                    getdatalist('num', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);
                    //getdatalist_bytime(filter.start_time, filter.end_time, 'num', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
                } else {
                    getdatalist('money', $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT);
                    //getdatalist_bytime(filter.start_time, filter.end_time, 'money', $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT);
                }
            });
            
        };
        //获取页签图
        var reportcharts = function () {

            var title = {1: $rootScope.language.TIP_REPORT_GUIDE_TODAY, 7: $rootScope.language.TIP_REPORT_GUIDE_WEEK, 30: $rootScope.language.TIP_REPORT_GUIDE_MONTH};
            var text_bar = '';
            var text_pie = '';
            if (search_type_bar == 0) {
                text_bar = $rootScope.language.TIP_REPORT_SALE_NUM;
            } else {
                text_bar = $rootScope.language.TIP_REPORT_SALE_NUM_MONEY;

            }
            if (search_type_pie == 0) {
                text_pie = $rootScope.language.TIP_REPORT_SALE_NUM_PERCENT;
            } else {
                text_pie = $rootScope.language.TIP_REPORT_SALE_MONEY_PERCENT;
            }

            dgyj_bar(day, title, text_bar, goods_bar);
            dgyj_pie(day, title, text_pie, goods_pie);

        };
        dgyj_init();
        //默认当天
        $scope.tab_dayd_list();
    }];
//支付构成分析
var ZfgcCtrl = ['$scope', '$rootScope', 'ReceiptRecord', 'ShopSetCheck', 'BaseDaoGou', 'timeStamp2String', 'Print','ngDialog','$timeout','printWaitMsg','closePrintWaitMsg',
    function ($scope, $rootScope, ReceiptRecord, ShopSetCheck, BaseDaoGou, timeStamp2String, Print,ngDialog,$timeout,printWaitMsg,closePrintWaitMsg) {
        $scope.curr = 'zfgc curr';
        //支付列表信息
        $scope.payment_list = {};

        //added by lqx maowei on 20170504 支付分析构成存放变量
        var payment_list_date = "";


        var goods_bar = {
            label: [],
            value: []
        };
        
        var reset = function () {
            $scope.payment_list = {};
            goods_bar = {
	            label: [],
	            value: []
	        };
        };
        
        //计算获取总计信息
        //add by liuwei 20171011 VIP积分置于最后
        var get_total_payment_data = function(ret){
            var coupon_ret = {}; //优惠券信息
            var vip_ret = {};//VIP积分
            var coupon_key = '';
            var result_ret = [];
            var total_payment_info = {};
            total_payment_info.trade_name = '总计';
            total_payment_info.trade_money = 0;

            $.each(ret,function(i,n){
                n.trade_code = i;
                if(i != '003' && i != '004' ){
                    result_ret.push(n);
                    total_payment_info.trade_money = parseFloat(total_payment_info.trade_money)+parseFloat(n.trade_money);
                }else if( i == '003'){
                    coupon_ret = n;
                    coupon_key = i;
                }else if( i == '004'){
                    vip_ret = n;
                }
            });
            total_payment_info.trade_code = 'zongji';
            result_ret.push(total_payment_info);
            result_ret.push({
                'trade_code':'kg',
                'trade_name':''
            });
            result_ret.push(coupon_ret);
            result_ret.push(vip_ret);
            return result_ret;
        };
        
        
        
        //获取支付列表信息
        var get_payment_list = function(){
            baison_app.api.showProgress({
				text: '',
				title: $rootScope.language.TIPS_DATA_NOT_DOWN,
				modal: false
			});
            ReceiptRecord.get_payment_list(time,'','').then(function(ret){
                baison_app.api.hideProgress();
                $scope.payment_list = get_total_payment_data(ret);
                reportcharts();
            }).catch(function(){
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
            });
        }; 
        var get_payment_list_by_time = function(){
            var s_start = $scope.start_time.toString();
            var s_end = $scope.end_time.toString();
            var start_time = new Date(s_start);
            var s_start_time = start_time.getTime();
            var end_time = new Date(s_end);
            var s_end_time = end_time.getTime();
            var start = timeStamp2String(s_start_time, 'datetime');
            var end = timeStamp2String(s_end_time, 'datetime');
            baison_app.api.showProgress({
				text: '',
				title: $rootScope.language.TIPS_DATA_NOT_DOWN,
				modal: false
			});
            ReceiptRecord.get_payment_list('',start, end).then(function (ret) {
                baison_app.api.hideProgress();
                //get_total_payment_data(ret);
                $scope.payment_list= get_total_payment_data(ret);
                payment_list_date = start.split(" ")[0] + "到" + end.split(" ")[0];
                reportcharts();
            }).catch(function(){
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET});
                baison_app.api.hideProgress();
            });
        };
        $scope.btn_search = function(){
            if(!$scope.start_time || !$scope.end_time){
                baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: "请输入日期"});
                return;
            }
            reset();
            get_payment_list_by_time();
        };      
        //当天页签
        $scope.tab_dayd_list = function () {
            $scope.dayd_cur = 1;
            $scope.weekd_cur = 0;
            $scope.monthd_cur = 0;
            time = timeStamp2String(0, 'date');
            day = 1;
            reset();
            get_payment_list();
            payment_list_date = "当天";            
        };
        //本周页签
        $scope.tab_weekd_list = function () {
            $scope.dayd_cur = 0;
            $scope.weekd_cur = 1;
            $scope.monthd_cur = 0;
            var now = new Date(); //当前日期   
            var nowDayOfWeek = now.getDay(); //今天本周的第几天  
            nowDayOfWeek = nowDayOfWeek == 0 ? 7 : nowDayOfWeek;
            var s_time = now.getTime() - (nowDayOfWeek - 1) * 1000 * 60 * 60 * 24;
            time = timeStamp2String(s_time, 'date');
            day = 7;
            reset();
            get_payment_list();
            payment_list_date = "本周";
        };
        //本月页签
        $scope.tab_monthd_list = function () {
            $scope.dayd_cur = 0;
            $scope.weekd_cur = 0;
            $scope.monthd_cur = 1;
            var myDate = new Date();
            var thisyear = myDate.getFullYear();
            var thismonth = myDate.getMonth() + 1;
            var s_time = thisyear + "-" + thismonth + "-1";
            time = timeStamp2String(s_time, 'date');
            day = 30;
            reset();
            get_payment_list();
            payment_list_date = "本月";
        };
		//获取页签图
        var reportcharts = function () {
            var text_bar = '支付构成';
            $.each($scope.payment_list,function(i,n){
            	if(n.trade_code && n.trade_code != 'zongji' && n.trade_code != 'kg'){
            		goods_bar.label.push(n.trade_name);
            		goods_bar.value.push(n.trade_money);
            	}
            });
            zfgc_bar(text_bar, goods_bar);	
        };
        //默认当天
        $scope.tab_dayd_list();
        //打印支付构成分析
        $scope.zfgc_print = function () {
			//add by liuwei on 20170527 打印控制
			var wait_data = printWaitMsg();
            Print.this_zfgc_print(payment_list_date, $scope.payment_list).then(function(){
				closePrintWaitMsg("success",wait_data,$scope.payment_list.length);
			}, function(){
				closePrintWaitMsg("fail",wait_data);
			});
        };
    }];
    
    
//零售按日分析
var LsfxCtrl = ['$scope', '$rootScope', 'BaseGoods', 'ngDialog', 'ReceiptRecord', 'ShopSetCheck', 'BaseDaoGou', 'timeStamp2String',
    function ($scope, $rootScope, BaseGoods, ngDialog, ReceiptRecord, ShopSetCheck, BaseDaoGou, timeStamp2String) {

        ShopSetCheck();
        $scope.curr = 'lsfx curr';

        var type = 'num';
        var day = 1;
        var search_type = 'num';
        var s_time = '';
        var window_id = 0;
        var goods_code = '';
        var lsfx_init = function () {
            $scope.money_cur = 0;
            $scope.num_cur = 1;
            $scope.shopcode_cur = 1;
            search_type = 'num';
            type = 'num';
            //选择代码
            $scope.shoptype_cur = 0;
            //选择类别

        };
        lsfx_init();

        $scope.filter = {};
        //获取大类
        BaseDaoGou.get_category_list_interface().then(function (response) {
            if (response.data.status == 1) {
                var data = response.data.data.data;
                $scope.filter.category = data;

            }
        }).catch(function (err) {
            //          baison_app.api.alert({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
            //              msg: err
            //          });
            baison_app.api.toast({
                title: $rootScope.language.COMMON_TITLE_HINT,
                msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
            });
            //'没有联网'
        });

        //获取小类
        BaseDaoGou.get_sort_list_interface().then(function (response) {
            if (response.data.status == 1) {
                var data = response.data.data.data;
                $scope.filter.sort = data;
            }
        }).catch(function (err) {
            //          baison_app.api.alert({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
            //              msg: err.msg
            //          });
            baison_app.api.toast({
                title: $rootScope.language.COMMON_TITLE_HINT,
                msg: $rootScope.language.MSG_NOT_CONNECTED_INTERNET
            });
            //'没有联网'
        });

        //        //商品分类页签
        //      $scope.tab_type_list = function (){
        //      	$scope.code_cur = 0;
        //	        $scope.type_cur = 1;
        //      };
        //商品数量
        $scope.tab_num_list = function () {
            $scope.money_cur = 0;
            $scope.num_cur = 1;
            $scope.btn_search();
            search_type = 'num';

        };

        //商品金额
        $scope.tab_money_list = function () {
            $scope.money_cur = 1;
            $scope.num_cur = 0;
            search_type = 'money';
            $scope.btn_search();

        };
        //商品代码
        $scope.cur_code = function () {
            $scope.shopcode_cur = 1;
            $scope.shoptype_cur = 0;
        }
        //商品类别
        $scope.cur_type = function () {
            $scope.shopcode_cur = 0;
            $scope.shoptype_cur = 1;
        }
        //重置变量

        var reset = function () {
            goods = {
                label: [],
                value: []
            };

        };

        //按商品代码
        var shop_code_show = function (s_start, s_end, s_start_time, s_end_time) {

            if ((s_end_time - s_start_time) > 30 * 1000 * 60 * 60 * 24) {
                //              s_end_time = s_start_time + 30 * 1000 * 60 * 60 * 24;
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_INPUT_DATE_MORE_MONTH
                });
                return;
            } else if ((s_end_time - s_start_time) < 0) {
                return;
            } else if ((s_end_time - s_start_time) == 0) {
                s_end_time = s_start_time + 1000 * 60 * 60 * 24;

            } else {
                s_end_time = s_end_time;
            }
            var a_start = new Date(s_start_time);
            var a_end = new Date(s_end_time);

            s_start = timeStamp2String(a_start, 'date');
            s_end = timeStamp2String(a_end, 'date');
            var count = [];

            var count_money = 0;
            var record_times = [];
            var new_data = [];
            ReceiptRecord.get_sku_by_goodscode(s_start, s_end, $scope.code_cur).then(function (ret) {

                if (ret.length == 0) {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_NOT_FOUND_GOODS});
                    return;
                } else if (ret.length > 1 && ret.length <= 5) {
                    $scope.goods_select_data = ret;
                    window_id = ngDialog.open({closeByDocument: false,
                        trapFocus: false,
                        template: './html/report/lsfx/goods_select.html',
                        disableAnimation: true,
                        scope: $scope,
                        controller: ['$scope', function ($scope) {
                                $scope.goods_select_click = function (g) {
                                    ngDialog.close(window_id);

                                    goods_code = g.goods_code;

                                    ReceiptRecord.get_goodsname_by_day(s_start, s_end, search_type, goods_code).then(function (ret) {

                                        if (ret.length > 0) {

                                            //获取数据
                                            for (var i = s_start_time; i <= s_end_time; i += 1000 * 60 * 60 * 24) {
                                                var i_time = timeStamp2String(i, 'date');
                                                $.each(ret, function (i, n) {
                                                    var record_time = timeStamp2String(n.record_time, 'date');
                                                    if (record_time == i_time) {
                                                        count.push({
                                                            time: i_time,
                                                            num: n.num,
                                                            money: n.money,
                                                            flag: 0
                                                        });

                                                    }

                                                })
                                            }

                                            //组装数据
                                            for (var i = 0; i < count.length; i++) {

                                                for (var j = i + 1; j < count.length; j++) {

                                                    if (count[j].time == count[i].time && count[j].flag != 1) {
                                                        count[i].num = parseInt(count[i].num) + parseInt(count[j].num);
                                                        count[i].money = parseInt(count[i].money) + parseInt(count[j].money);
                                                        count[j].flag = 1;
                                                    }
                                                }
                                            }
                                            count.forEach(function (n) {
                                                if (n.flag == 0) {
                                                    new_data.push(n);
                                                }
                                            });


                                            //根据标签传数据

                                            if (search_type == 'num') {
                                                for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                                                    var i_time = timeStamp2String(i, 'date');
                                                    for (var j = 0; j < new_data.length; j++) {
                                                        if (new_data[j].time == i_time) {
                                                            goods.value[index] = new_data[j].num;
                                                        }
                                                    }
                                                    index++;

                                                }

                                            }
                                            if (search_type == 'money') {
                                                for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                                                    var i_time = timeStamp2String(i, 'date');
                                                    for (var j = 0; j < new_data.length; j++) {
                                                        if (new_data[j].time == i_time) {
                                                            goods.value[index] = new_data[j].money;
                                                        }
                                                    }
                                                    index++;

                                                }

                                            }
                                            reportcharts();



                                        } else {
                                            baison_app.api.toast({
                                                buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                                title: $rootScope.language.COMMON_TITLE_HINT,
                                                msg: $rootScope.language.TIP_REPORT_SALE_HOT
                                            });
                                            reportcharts();
                                        }

                                    });
                                }
                            }]
                    });
                } else if (ret.length == 1) {
                    goods_code = ret[0].goods_code;
                    ReceiptRecord.get_goodsname_by_day(s_start, s_end, search_type, goods_code).then(function (ret) {
            
                        //added by lqx maowei on 20170418
                        $scope.goodsInfo = ret[0];
                     
                        if (ret.length > 0) {

                            //获取数据
                            for (var i = s_start_time; i <= s_end_time; i += 1000 * 60 * 60 * 24) {
                                var i_time = timeStamp2String(i, 'date');
                                $.each(ret, function (i, n) {
                                    var record_time = timeStamp2String(n.record_time, 'date');
                                    if (record_time == i_time) {
                                        count.push({
                                            time: i_time,
                                            num: n.num,
                                            money: n.money,
                                            flag: 0
                                        });

                                    }

                                })
                            }

                            //组装数据
                            for (var i = 0; i < count.length; i++) {

                                for (var j = i + 1; j < count.length; j++) {

                                    if (count[j].time == count[i].time && count[j].flag != 1) {
                                        count[i].num = parseInt(count[i].num) + parseInt(count[j].num);
                                        count[i].money = parseInt(count[i].money) + parseInt(count[j].money);
                                        count[j].flag = 1;
                                    }
                                }
                            }
                            count.forEach(function (n) {
                                if (n.flag == 0) {
                                    new_data.push(n);
                                }
                            });


                            //根据标签传数据

                            if (search_type == 'num') {
                                for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                                    var i_time = timeStamp2String(i, 'date');
                                    for (var j = 0; j < new_data.length; j++) {
                                        if (new_data[j].time == i_time) {
                                            goods.value[index] = new_data[j].num;
                                        }
                                    }
                                    index++;

                                }

                            }
                            if (search_type == 'money') {
                                for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                                    var i_time = timeStamp2String(i, 'date');
                                    for (var j = 0; j < new_data.length; j++) {
                                        if (new_data[j].time == i_time) {
                                            goods.value[index] = new_data[j].money;
                                        }
                                    }
                                    index++;

                                }

                            }
                            reportcharts();



                        } else {
                            baison_app.api.toast({
                                buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                                title: $rootScope.language.COMMON_TITLE_HINT,
                                msg: $rootScope.language.TIP_REPORT_SALE_HOT
                            });
                            reportcharts();
                        }

                    });
                } else {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_GOODS_MORE_INPUT_CODE});
                    return;
                }
            });


        };

        //按类别
        var shop_type_show = function (s_start, s_end, s_start_time, s_end_time) {

            if ((s_end_time - s_start_time) > 30 * 1000 * 60 * 60 * 24) {
                //              s_end_time = s_start_time + 30 * 1000 * 60 * 60 * 24;
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_INPUT_DATE_MORE_MONTH
                });
                return;
            } else if ((s_end_time - s_start_time) < 0) {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIPS_CUNHUO_MESSAGE_TIME_LIMIT
                });
                return;
            } else if ((s_end_time - s_start_time) == 0) {
                s_end_time = s_start_time + 1000 * 60 * 60 * 24;

            } else {
                s_end_time = s_end_time;
            }
            var ss_start = timeStamp2String(s_start_time, 'date');
            var ss_end = timeStamp2String(s_end_time, 'date');
            ReceiptRecord.get_goodsname_by_type(ss_start, ss_end, search_type, $scope.cate_date.category_code, $scope.sort_date.sort_code).then(function (ret) {

                if (ret.length > 0) {

                    for (var i = s_start_time; i <= s_end_time; i += 1000 * 60 * 60 * 24) {
                        var i_time = timeStamp2String(i, 'date');
                        $.each(ret, function (i, n) {
                            var record_time = timeStamp2String(n.record_time, 'date');
                            if (record_time == i_time) {
                                count.push({
                                    time: i_time,
                                    num: n.num,
                                    money: n.money,
                                    flag: 0
                                });

                            }

                        })
                    }

                    //组装数据
                    for (var i = 0; i < count.length; i++) {

                        for (var j = i + 1; j < count.length; j++) {

                            if (count[j].time == count[i].time && count[j].flag != 1) {
                                count[i].num = parseInt(count[i].num) + parseInt(count[j].num);
                                count[i].money = parseInt(count[i].money) + parseInt(count[j].money);
                                count[j].flag = 1;
                            }
                        }
                    }
                    count.forEach(function (n) {
                        if (n.flag == 0) {
                            new_data.push(n);
                        }
                    });

                    //根据标签传数据

                    if (search_type == 'num') {
                        for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                            var i_time = timeStamp2String(i, 'date');
                            for (var j = 0; j < new_data.length; j++) {
                                if (new_data[j].time == i_time) {
                                    goods.value[index] = new_data[j].num;
                                }
                            }
                            index++;

                        }

                    }
                    if (search_type == 'money') {
                        for (var i = s_start_time, index = 0; i <= s_end_time; i += 1000 * 60 * 60 * 24) {

                            var i_time = timeStamp2String(i, 'date');
                            for (var j = 0; j < new_data.length; j++) {
                                if (new_data[j].time == i_time) {
                                    goods.value[index] = new_data[j].money;
                                }
                            }
                            index++;

                        }

                    }
                    reportcharts();

                }

            });

        }
        //查询按钮
        $scope.btn_search = function () {
            $scope.start_time
            $scope.end_time

            reset();

            if (typeof $scope.start_time == 'undefined' || typeof $scope.end_time == 'undefined') {
                baison_app.api.toast({
                    buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                    title: $rootScope.language.COMMON_TITLE_HINT,
                    msg: $rootScope.language.TIP_REPORT_TIME
                });
                return;
            }
            ;
            var s_start = ($scope.start_time).toString();
            var s_end = ($scope.end_time).toString();

            //计算时间（一个月以内）
            var start_time = new Date(s_start);
            var s_start_time = start_time.getTime();

            var end_time = new Date(s_end);
            var s_end_time = end_time.getTime();

            for (var i = s_start_time; i <= s_end_time; i += 1000 * 60 * 60 * 24) {
                var time = i;
                s_time = timeStamp2String(time, 'date');
                goods.label.push(s_time);
                goods.value.push('0');
            }
            if ($scope.shopcode_cur == 1) {
                var key = new String($scope.code_cur);
                if (typeof $scope.code_cur == 'undefined') {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIP_REPORT_CODE
                    });
                    return;
                }
                if ('' == $scope.code_cur || key.length < 3) {
                    baison_app.api.toast({buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON], title: $rootScope.language.COMMON_TITLE_HINT, msg: $rootScope.language.MSG_INPUT_MORE_THREE
                    });
                    return;
                }
                $scope.shoptype_cur = 0;
                shop_code_show(s_start, s_end, s_start_time, s_end_time);
            }
            ;
            if ($scope.shoptype_cur == 1) {
                if (typeof $scope.cate_date == 'undefined' || typeof $scope.sort_date == 'undefined') {
                    baison_app.api.toast({
                        buttons: [$rootScope.language.COMMON_CONFIRM_BUTTON],
                        title: $rootScope.language.COMMON_TITLE_HINT,
                        msg: $rootScope.language.TIP_REPORT_TYPE
                    });
                    return;
                }
                ;
                $scope.shopcode_cur = 0;
                shop_type_show(s_start, s_end, s_start_time, s_end_time);
            }
        };

        //默认商品代码。
        //      $scope.tab_code_list();
        var reportcharts = function () {
            var text = '';
            if (search_type == 'num') {
                text = $rootScope.language.TIP_REPORT_SALE_NUM;
            } else {
                text = $rootScope.language.TIP_REPORT_SALE_NUM_MONEY;
            }

            lsfx_bar(text, goods);

        };
        //默认金额
        //    $scope.tab_money_list();

    }];
//更多报表
var MoreReportCtrl = ['$scope', '$rootScope', function ($scope, $rootScope) {
        $scope.curr = 'more curr';
    }];

ReportIndexCtrl.$injector = ['$scope', '$rootScope'];
SpkcCtrl.$injector = ['$scope', '$rootScope', 'BaseGoods', 'ngDialog', '$rootScope', '$location'];
KczfxCtrl.$injector = ['$q', '$scope', '$rootScope', 'BaseGoods','timeStamp2String','Print','dbGetOne','ngDialog','$timeout','printWaitMsg','closePrintWaitMsg'];
JxcfxCtrl.$injector = ['$scope', '$rootScope', 'changeDate', 'Report', 'ngDialog', 'timeStamp2String'];
ArfxCtrl.$injector = ['$scope', '$rootScope', 'PosUser', 'timeStamp2String'];
RxphCtrl.$injector = ['$scope', '$rootScope', 'ShopSetCheck', 'ReceiptRecord', 'timeStamp2String'];
DgyjCtrl.$injector = ['$scope', '$rootScope','$q', 'ShopSetCheck', 'ReceiptRecord', 'timeStamp2String','VIP'];
ZfgcCtrl.$injector = ['$scope', '$rootScope', 'ReceiptRecord', 'ShopSetCheck', 'BaseDaoGou', 'timeStamp2String','ngDialog','$timeout','printWaitMsg','closePrintWaitMsg'];
LsfxCtrl.$injector = ['$scope', '$rootScope', 'BaseGoods', 'ngDialog', 'ReceiptRecord', 'ShopSetCheck', 'BaseDaoGou', 'timeStamp2String'];
MoreReportCtrl.$injector = ['$scope', '$rootScope' ];